package com.joolun.web.controller.scrm;

import com.joolun.common.annotation.Log;
import com.joolun.common.core.controller.BaseController;
import com.joolun.common.core.domain.AjaxResult;
import com.joolun.common.core.page.TableDataInfo;
import com.joolun.common.enums.BusinessType;
import com.joolun.common.utils.poi.ExcelUtil;
import com.joolun.system.domain.ScrmPlanLink;
import com.joolun.weixin.service.IScrmPlanLinkService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 渠道链接Controller
 * 
 * @author joolun
 * @date 2025-03-10
 */
@RestController
@RequestMapping("/system/link")
public class ScrmPlanLinkController extends BaseController
{
    @Autowired
    private IScrmPlanLinkService scrmPlanLinkService;

    /**
     * 查询渠道链接列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ScrmPlanLink scrmPlanLink)
    {
        startPage();
        List<ScrmPlanLink> list = scrmPlanLinkService.selectScrmPlanLinkList(scrmPlanLink);
        return getDataTable(list);
    }

    /**
     * 导出渠道链接列表
     */
    @PreAuthorize("@ss.hasPermi('system:link:export')")
    @Log(title = "渠道链接", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScrmPlanLink scrmPlanLink)
    {
        List<ScrmPlanLink> list = scrmPlanLinkService.selectScrmPlanLinkList(scrmPlanLink);
        ExcelUtil<ScrmPlanLink> util = new ExcelUtil<ScrmPlanLink>(ScrmPlanLink.class);
        util.exportExcel(response, list, "渠道链接数据");
    }

    /**
     * 获取渠道链接详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scrmPlanLinkService.selectScrmPlanLinkById(id));
    }

    /**
     * 新增渠道链接
     */
    @PreAuthorize("@ss.hasPermi('system:link:add')")
    @Log(title = "渠道链接", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScrmPlanLink scrmPlanLink)
    {
        scrmPlanLink.setCreateBy(getUsername());
        return toAjax(scrmPlanLinkService.insertScrmPlanLink(scrmPlanLink));
    }

    /**
     * 修改渠道链接
     */
    @PreAuthorize("@ss.hasPermi('system:link:edit')")
    @Log(title = "渠道链接", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScrmPlanLink scrmPlanLink)
    {
        scrmPlanLink.setCreateBy(getUsername());
        return toAjax(scrmPlanLinkService.updateScrmPlanLink(scrmPlanLink));
    }

    /**
     * 删除渠道链接
     */
    @PreAuthorize("@ss.hasPermi('system:link:remove')")
    @Log(title = "渠道链接", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scrmPlanLinkService.deleteScrmPlanLinkByIds(ids));
    }
}
